/**
 * 站点信息
 */
let mongoose = require('../mongodb.js'), Schema = mongoose.Schema;

let OptionSchema = new Schema({
	// 评论所在的文章_id，0代表系统留言板
	post_id: { type: Number, required: true },

	// pid，0代表默认留言
	pid: { type: Number, default: 0 },

	// content
	content: { type: String, required: true, validate: /\S+/ },

	// 被赞数
	likes: { type: Number, default: 0 },

	// ip
	ip: { type: String },

	// ip 物理地址
	city: { type: String },
	range: { type: String },
	country: { type: String },

	// 用户ua
	agent: { type: String, validate: /\S+/ },

	// 评论产生者
	author: {
		name: { type: String, required: true, validate: /\S+/ },
		email: { type: String, required: true, validate: /\w[-\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\.)+[A-Za-z]{2,14}/ },
		// tslint:disable-next-line:max-line-length
		site: {
			type: String,
			validate: /^((https|http):\/\/)+[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/
		}
	},

	// 状态 0待审核 1通过正常 2不通过
	state: { type: Number, default: 1 },

	// 发布日期
	create_at: { type: Date, default: Date.now() },

	// 最后修改日期
	update_at: { type: Date, default: Date.now() }
});

module.exports = mongoose.model('User', OptionSchema);